//
//  LHSkuView.m
//  lehuotest
//
//  Created by ice on 2017/1/3.
//  Copyright © 2017年 QF. All rights reserved.
//

#import "LHSkuView.h"
#import "LHNumberView.h"
#import "HomeGetAttrModel.h"
#import "LHSpecHeaderCell.h"
#import "LHSkuCell.h"
#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
@interface  LHSkuView()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong)  LHNumberView *numberView;

@property (nonatomic, weak) IBOutlet UIButton *sureBtn;

@property (nonatomic, weak) IBOutlet UITableView *table;

//@property (nonatomic, weak) IBOutlet UIScrollView *scroll;
@end

@implementation LHSkuView

-(LHNumberView *)numberView
{
    if (!_numberView){
        _numberView = [LHNumberView loadFromNib];
    }
    return _numberView;
}

+(instancetype) loadFromNib
{
    NSString *xibName = NSStringFromClass([self class]);
    return [[[NSBundle mainBundle] loadNibNamed:xibName owner:nil options:nil] firstObject];
}

-(void) awakeFromNib
{
    [super awakeFromNib];
    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 60)];
    footerView.backgroundColor = [UIColor whiteColor];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, 100, 20)];
    label.text = @"数量";
    label.textColor = [UIColor blackColor];
    label.font = [UIFont systemFontOfSize:14];
    [footerView addSubview:label];
    self.numberView.frame = CGRectMake(SCREEN_WIDTH-110, 15, 100, 30);
    [footerView addSubview:self.numberView];
    self.table.tableFooterView = footerView;
    
    
    [self.sureBtn addTarget:self action:@selector(sureBtnAction) forControlEvents:UIControlEventTouchUpInside];
    
    
    self.table.delegate = self;
    self.table.dataSource = self;
    self.table.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.table.backgroundColor = [UIColor clearColor];
    
    
}
-(void) setDataSource:(NSArray *)dataSource
{
    _dataSource = dataSource;
    
    [self.table reloadData];
}
-(void) sureBtnAction
{
    if (self.sureBtnTap){
        self.sureBtnTap();
    }
}
#pragma mark - UITableViewDelegate && UITableViewDataSource
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.dataSource.count;
}

-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0){
        LHSpecHeaderCell *cell = [LHSpecHeaderCell initWithTableView:tableView];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    
    LHSkuCell *cell = [LHSkuCell initWithTableView:tableView];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    HomeGetAttrModel *model = self.dataSource[indexPath.section];
    cell.skus = model.values;
    return cell;
    
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"emptyCell"];
//    if (cell == nil){
//        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"emptyCell"];
//    }
//    cell.backgroundColor = [UIColor greenColor];
//    return cell;
}
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0){
        return [LHSpecHeaderCell CellDefaultHeight];
    }
    HomeGetAttrModel *model = self.dataSource[indexPath.section];
    return [LHSkuCell CellDefaultHeight:model.values];
}
-(void) dealloc
{
    self.sureBtnTap = nil;
}

//自装需要带的东西  合同 身份证原件 一个布局图 一个水电图   8:00-12:00   14:00-17:00
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
